/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jl.tools.stkeditor.generate;

import com.jl.tools.stkeditor.exception.DataNotMatchCodingScheamException;
import com.jl.util.HexUtil;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author LuHongjun
 */
public final class AddItemTag extends CodeDect {

  private int index;

  public AddItemTag(Code code, int index) {
    this.code = code;
    this.index = index;
  }

  @Override
  public List<String> getCode() throws DataNotMatchCodingScheamException {
    List<String> l = new ArrayList<String>();

    l.addAll(genTag());
    l.addAll(code.getCode());
    return l;
  }

  @Override
  public int getLength() {
    return code.getLength() + 3;
  }

  private List<String> genTag() {
    List<String> l = new ArrayList<String>();
    l.add("8F");
    l.add(HexUtil.toHexXX(code.getLength() + 1));
    l.add(HexUtil.toHexXX(index));
    return l;
  }
}
